package com.edu.test;

import com.edu.bean.*;
import com.edu.mapper.CourseMapper;
import com.edu.mapper.DepartMapper;
import com.edu.mapper.ScoreMapper;
import com.edu.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

/**
 * @Author:zyn
 * @Date:2025/10/11--21:24:37
 */
public class MyTest02 {
    private SqlSession session = null;

    @Before
    public void init() throws Exception{
        String path = "mybatis-config.xml";
        InputStream ins = Resources.getResourceAsStream(path);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(ins);
        session = sqlSessionFactory.openSession();
    }
    @Test
    public void test01(){
        DepartMapper departMapper = session.getMapper(DepartMapper.class);
        Depart depart = departMapper.selectDepartById(5);
        System.out.println(depart);
        System.out.println(depart.getEmpList());
    }

    @Test
    public void test02(){
        DepartMapper departMapper = session.getMapper(DepartMapper.class);
        List<Depart> departList = departMapper.selectAll();
        for (Depart depart : departList) {
            System.out.println(depart);
            for (Emp emp : depart.getEmpList()) {
                System.out.println(emp);
            }
            System.out.println("---------------------");
        }
    }

    //思考
    @Test
    public void test03(){
        DepartMapper departMapper = session.getMapper(DepartMapper.class);
        Depart depart = departMapper.selectDepartById2(3);
        System.out.println(depart);
        System.out.println(depart.getEmpList());
        System.out.println(depart.getEmpList().get(0));
        System.out.println(depart.getEmpList().get(0).getDepart());
        System.out.println(depart.getEmpList().get(0).getDepart().getEmpList());
    }


}
